<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查找次数出现最多的元素</title>
</head>
<body>
<script type="text/javascript">
    var str="sajhdjsbcfhjbsjdfjshd";
    var json={};
    for(var i=0;i<str.length;i++){
        if(json[str.charAt(i)]){
            json[str.charAt(i)]++;
        }else{
            json[str.charAt(i)]=1;
        }
    }
    var num=0;
    var n;
    for(var key in json){
        if(json[key]>num){
            num=json[key];
            n=key;
        }
    }
    console.log(n,num);
</script>
</body>
</html>